package com.htc.model.utils;

import android.content.Context;
import android.database.Cursor;

import com.htc.common.ActionEvent;
import com.htc.constants.Constants;
import com.htc.controller.AboutsController;
import com.htc.controller.KidsController;
import com.htc.dlc.fragment.FragmentAboutClup;
import com.htc.dlc.fragment.FragmentAboutGrace;
import com.htc.model.dto.KidsDTO;

public class KidsModel {
	public static KidsModel instance;

	public static KidsModel getInstance() {
		if (instance == null)
			instance = new KidsModel();
		return instance;
	}

	public void handleControllerEvent(ActionEvent e) {
		KidsDTO kids;
		switch (e.action) {
		case Constants.GET_ALL_KIDS:
			kids = getAllKids((Context) e.sender);
			e.viewData = kids;
			KidsController.getInstance().handleModelViewEvent(e);
			break;
		default:
			break;
		}
	}

	private KidsDTO getAllKids(Context context) {
		KidsDTO dto = new KidsDTO();
		String sql = "SELECT * from kids";

		DBHelper db = DBHelper.getInstance(context);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {

			dto.setId(c.getString(c.getColumnIndex("kid_id")));
			dto.setDescription(c.getString(c.getColumnIndex("description")));
		}
		c.close();
		db.close();
		return dto;
	}
}
